package com.wx.leetcode;

/**
 * @desc: 盛最多水的容器
 *   计算值 * 下标最大的值
 *
 * @author: wx
 * @time: 2020/4/21 6:37 PM
 */
public class MaxAreaTopic {

    public static int maxArea(int[] height) {

        //抽象左右两个边界下标
        int start = 0;
        int end = height.length - 1;

        int ans = 0;

        while (start < end){

            int min = Math.min(height[start], height[end]) * (end - start);
            ans = Math.max(ans,min);

            //大的一方，下标不移动
            if (height[start] <= height[end]){
                ++start;
            } else {
                --end;
            }
        }

        return ans;

    }
    
    public static void main(String args[]) { 
      int[] nums = new int[]{1,8,6,2,5,4,8,3,7};
        System.out.println(maxArea(nums));
    } 
    

}
